package cn.com.huzo.webapp.controller.purchase;

import cn.com.huzo.model.entities.purchase.PoNoticeEntity;
import cn.com.huzo.service.purchase.PoNoticeManager;
import huzofw.common.web.controller.BaseFormController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 采购下单通知画面控制器
 *
 * @author 吴旭
 */
@Controller
public class PoNoticeController extends BaseFormController {

    // <editor-fold defaultstate="collapsed" desc="属性">
    @Resource(name = "PoNoticeManager")
    private PoNoticeManager _manager_po_notice;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 跳转到采购下单通知一览画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("purchase/po_notice/list.html")
    public ModelAndView redirectListWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("purchase.po_notice.list.def");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="数据处理部分">
    /**
     * 根据条件取得采购下单通知信息分页数据。
     * <p>
     * @param criterion 检索条件
     * @return 采购下单通知信息分页数据
     * @throws Exception
     */
    @RequestMapping(value = "purchase/po_notice/fetchForPage.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> fetchForPage(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_po_notice.fetchForPage(criterion);
    }

    /**
     * 更新采购下单通知信息数据（更新完成标记）。
     * <p>
     * @param criterion 要保存的采购下单通知信息对象。
     * @return 新增记录主键.
     * @throws Exception
     */
    @RequestMapping(value = "purchase/po_notice/setReceiptedFlag.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Integer setReceiptedFlag(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_po_notice.setReceiptedFlag(
                MapUtils.getString(criterion, "PoNoticeId"),
                MapUtils.getShort(criterion, "MrpType")
        );
    }

    /**
     * 设置采购担当自己负责部分的下单完成标记信息。
     * <p>
     * @param criterion 要保存的采购下单通知信息对象。
     * @return 新增记录主键.
     * @throws Exception
     */
    @RequestMapping(value = "purchase/po_notice/setOverFlag.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Integer setOverFlag(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_po_notice.setOverFlag(
                MapUtils.getString(criterion, "PoNoticeId"),
                MapUtils.getShort(criterion, "MrpType"),
                MapUtils.getString(criterion, "OverFlag")
        );
    }

    /**
     * 发送采购通知
     * <p>
     * @param itemList 要发送的采购担当及款号等信息。
     * @return 已发送的采购担当
     * @throws Exception
     */
    @RequestMapping(value = "purchase/po_notice/sendPoNotice.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> sendPoNotice(@RequestBody final List<PoNoticeEntity> itemList) throws Exception {
        Map<String, Object> _result = new HashMap();
        _result.put("Result", _manager_po_notice.sendPoNotice(itemList));
        return _result;
    }
    // </editor-fold>
}
